(function($) {
    $.toolslogin = {
        getLogin : function() { //调用案例：$.toolslogin.getLogin();
            return getLogin();
        },
        dologin:function () {
            dologin();
        }
    };

    /**
     * 获取用户是否登录
     * 返回格式：json对象
     * 未登录：{ isLogin: false }
     * 已登录：{ isLogin: true, loginUserId: "e0d4adc****db660", loginUserEname: "test", loginUserCname: "测试用户" }
     */
    function getLogin() {
        var loginMap = {};
        loginMap["isLogin"]=false;
        var loginUserEname = $("input[type='hidden'][name='top_login_frame_user_ename']").val();
        var loginUserId = $("input[type='hidden'][name='top_login_frame_user_id']").val();
        var loginUserCname = $("input[type='hidden'][name='top_login_frame_user_cname']").val();
        var loginUserCustomerType= $("input[type='hidden'][name='top_login_frame_user_customer_type']").val();
        var loginUserUserType= $("input[type='hidden'][name='top_login_frame_user_type']").val();
        var loginUserActJsonStr= $("input[type='hidden'][name='top_login_frame_user_act']").val();
        if(strIsNull(loginUserEname)){
            var _cookie_uename = $.cookie('_uc.sso');
            // console.log("_cookie_uename",_cookie_uename);
            if(!strIsNull(_cookie_uename)){
                loginUserEname =_cookie_uename;
                $.ajax({type: 'post',url: ctx+"/res/uct/userInfo",async:false,data: {"username":loginUserEname},dataType: 'json',success: function (myData) {
                    if(myData.flag=="T" && !strIsNull(myData.msg)){
                        var jsonObj = jQuery.parseJSON(myData.msg);
                         // console.log(myData);
                        loginUserId=jsonObj.userId;
                        loginUserCname=jsonObj.userCname;
                        loginUserCustomerType=jsonObj.customerType;
                        loginUserUserType=jsonObj.userType;
                        // loginUserActJsonStr=jQuery.parseJSON(jsonObj.actJsonStr);
                    }
                }});
			}
        }
        if(!strIsNull(loginUserEname)){
            loginMap["isLogin"]=true;
            loginMap["loginUserId"]=loginUserId;
            loginMap["loginUserEname"]=loginUserEname;
            loginMap["loginUserCname"]=loginUserCname;
            loginMap["loginUserCustomerType"]=loginUserCustomerType;
            loginMap["loginUserUserType"]=loginUserUserType;
            loginMap["loginUserActJsonStr"]=loginUserActJsonStr;
        }
        // console.log("loginMap",loginMap);
        return loginMap;
    }

    //登录校验
    function dologin(){
        if(strIsNull($("#login_username").val())){
            layer.tips('请输入登录名！', '#login_username', {tips: 1});
            $("#login_username").focus();
            return;
        }
        if(strIsNull($("#login_password").val())){
            layer.tips('请输入密码！', '#login_password', {tips: 1});
            $("#login_password").focus();
            return;
        }
        $("#userEname").val($("#login_username").val().trim());
        $("#userPwd").val($("#login_password").val().md5());
        var formUrl =ctx+"/res/uct/login";
        var result = $.platform.submit({formId:'loginForm',dataType:'json',url:formUrl});
        opDone(result.flag,result.msg);
    }

})(jQuery);

$(function(){

	//登录
	$("#btn-login").click(function() {
        $.toolslogin.dologin();
	});
	//进入用户中心
	$("#btn-my-home").click(function() {
		window.location.href="sendPage/default/web/user/index";
	});
	//进入业务管理中心
	$("#btn-admin-home").click(function() {
		window.location.href="sendPage/default/admin/index";
	});
	//注册v1-普通注册
	$("#frm1_btn_reg").click(function() {
		checkReg("none","frm1");
	});
	//注册v2-手机号注册
	$("#frm2_btn_reg").click(function() {
		checkReg("moblie","frm2");
	});
	//注册v1-个人注册
	$("#frm1_btn_regT").click(function() {
		checkRegT("mobile","frm1");
	});
	//注册v2-企业注册
	$("#frm2_btn_regT").click(function() {
		checkRegT("moblie","frm2");
	});
	//找回密码申请
	$("#frm_btn_findpass").click(function() {
		//old 邮箱找回
		//checkFindPassByEmail();
		//bjte 短信找回
		checkFindPassByMobile();
	});
	//找回密码-重新设置新密码
	$("#frm_btn_findpass_sub").click(function() {
		checkFindPassSub();
	});
});


//注册校验
/*
function checkReg(type,formId){
	var userNameId ="#"+formId+"_login_username";
	var passId ="#"+formId+"_login_password"; 
	var passId2 ="#"+formId+"_login_password2"; 
	var checkCodeId ="#"+formId+"_login_checkcode"; 
	if(strIsNull($(userNameId).val())){
		layer.tips($(userNameId).attr("tip"), userNameId, {tips: 1});
		$(userNameId).focus();
		return;
	}
	if(/.*[\u4e00-\u9fa5]+.*$/.test($(userNameId).val())){
		layer.tips('登录名不能包含中文！', userNameId, {tips: 1});
		$(userNameId).focus();
		return;
	} 
	if($(userNameId).val().length<6){
		layer.tips("您的登录名太短", userNameId, {tips: 1});
		$(userNameId).focus();
		return;
	}
	if(strIsNull($(passId).val())){
		layer.tips($(passId).attr("tip"), passId, {tips: 1});
		$(passId).focus();
		return;
	}
	if(!/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/ .test($(passId).val())){
		layer.tips('请输入6-24位密码，必须由数字和英文字母组成！', passId, {tips: 1});
		$(passId).focus();
		return;
	}
	if(strIsNull($(passId2).val())){
		layer.tips($(passId2).attr("tip"), passId2, {tips: 1});
		$(passId2).focus();
		return;
	}
	if($(passId).val()!=$(passId2).val()){
		layer.tips("两次输入的密码不一致", passId2, {tips: 1});
		$(passId2).val("");
		$(passId2).focus();
		return;
	}
	if(strIsNull($(checkCodeId).val())){
		layer.tips($(checkCodeId).attr("tip"), checkCodeId, {tips: 1});
		$(checkCodeId).focus();
		return;
	}
	$("#userEname").val($(userNameId).val().trim());
	$("#userPwd").val($(passId).val().md5());
	$("#userPwd2").val($(passId2).val().md5());
	$("#userRand").val($(checkCodeId).val());
	if ("moblie"==type) {
		$("#mobile").val($(userNameId).val().trim());
	}
	var formUrl =ctx+"/res/uct/regUser";//统一注册form表单dymicSql
	var index_load = layer.load(1, {shade: false});
	var result = $.platform.submit({formId:"regform_s",dataType:"json",url:formUrl});
	var flag = result.flag;
	var msg = result.msg;
	if("T"==flag){
		layer.close(index_load);
		layer.msg("注册成功，您可以登录了，3秒后自动关闭！", {offset: '200px'},function(){
			//parent.layer.closeAll();
			window.location.href="/";
		});
	}else{
		layer.close(index_load);
		layer.msg(result.msg, {offset: '200px'});
	}
}
*/
//注册校验
function checkRegT(type,formId){
	var userNameId ="#"+formId+"_login_username";
	var passId ="#"+formId+"_login_password"; 
	var passId2 ="#"+formId+"_login_password2"; 
	var userCname = "#"+formId+"_login_usercname";
	var mobile ="#"+formId+"_login_mobile";
	var checkCodeId ="#"+formId+"_login_checkcode"; 
	var linkName ="#"+formId+"_login_linkName"; 
	
	//身份证
	var certNo = "#certNo";
	//注册来源 0 前台 1 后台 2 微信
	var infoFrom = $("#"+formId).find("input[name='member.infoFrom']").val();
	//类型
	var memberType = $("#"+formId).find("input[name='member.memberType']").val();
	//校验登录名
	if(strIsNull($(userNameId).val())){
		layer.tips($(userNameId).attr("tip"), userNameId, {tips: 1});
		$(userNameId).focus();
		return false;
	}
	
	//校验用户名是否存在
	if(!checkUserEname('frm1')){
		//layer.msg("用户名已存在！", {offset: '200px'});
		return false;
	}
	if(!/^\w{6,20}/.test($(userNameId).val())){
		layer.tips('请输入6-20位数字字母下划线！', userNameId, {tips: 1});
		$(userNameId).focus();
		return false;
	}
	//校验密码
	if(!/^(?=.*[0-9])(?=.*[a-zA-Z]).{6,12}$/.test($(passId).val())){
		layer.tips('请输入6-12位密码，必须由数字和英文字母组成！', passId, {tips: 1});
		$(passId).focus();
		return false;
	}
	if($(passId).val()!=$(passId2).val()){
		layer.tips("两次输入的密码不一致", passId2, {tips: 1});
		$(passId2).val("");
		$(passId2).focus();
		return false;
	}
	//校验会员名
	if(strIsNull($(userCname).val())){
		layer.tips($(userCname).attr("tip"), userCname, {tips: 1});
		$(userCname).focus();
		return false;
	}
	if(!/^[^\s]{2,20}$/.test($(userCname).val())){
		layer.tips('请输入2-20位字符,不能包含空格！', userCname, {tips: 1});
		$(userCname).focus();
		return false;
	}
	//判断是否为个人 身份证校验
	if(memberType=="person"){
		if(strIsNull($(certNo).val())){
			layer.tips("请输入身份证号码", certNo, {tips: 1});
			$(certNo).focus();
			return false;
		}
		if(!IdentityCodeValid($(certNo).val())){
			layer.tips($(certNo).attr("tip"), certNo, {tips: 1});
			$(certNo).focus();
			return false;
		}
	}else{
		//校验联系人名称
		if(strIsNull($(linkName).val())){
			layer.tips($(linkName).attr("tip"), linkName, {tips: 1});
			$(linkName).focus();
			return false;
		}
	}
	//校验手机号是否存在
	if(!checkUserMobile(formId,1)){
		return false;
	}
	//验证验证码 判断注册来源0 前台 1后台 2微信
	if(infoFrom=="0"){
		if(strIsNull($(checkCodeId).val())){
			layer.tips($(checkCodeId).attr("tip"), checkCodeId, {tips: 1});
			$(checkCodeId).focus();
			return false;
		}else{//这里提供给前台用户注册，第一步校验；然后第二步提交在前台自己完成
			return true;
		}
	}
	//密码进行md5加密
	$(passId).val($(passId).val().md5());
	$(passId2).val($(passId2).val().md5());
	if ("moblie"==type) {
		$("#mobile").val($(userNameId).val().trim());
	}
	var formUrl =ctx+"/res/uct/dymicSql";
	var to_url = "";
	var infoForm = $("input[name='member.infoForm']").val();
	if(infoForm=="1"){
		to_url=ctx+"/sendPage/bjte/admin/member/member-audit-list";
	}else if(infoForm=="2"){
		to_url=ctx+"/sendPage/sale/admin/trader/trader-audit-list";
	}else{
		to_url="/";
	}
	var index_load = layer.load(1, {shade: false});
	var result = $.platform.submit({formId:formId,dataType:"json",url:reg_url});
	var flag = result.flag;
	var msg = result.msg;
	if("T"==flag){
		layer.close(index_load);
			layer.alert("注册成功，请等待交易所审核！", {offset: '200px'},function(){
				window.location.href=to_url;
			});
	}else{
		$(passId).val("");
		$(passId2).val("");
		layer.close(index_load);
		layer.msg(result.msg, {offset: '200px'});
	}
}
//按钮-发送验证码
//type 1-注册 2-找回密码 3-重新绑定
function countSecond(obj,formId,type,timer) {
	if(timer == undefined){
		//根据type类型返回对应提示信息
		if(!checkUserMobile(formId,type)){
			return false;
		} 
		sendSmsRand(formId,type);
		timer=60;
	}
	if(timer==0){
		$(obj).text("重新发送");
		$(obj).attr("disabled",false);
    }
    if (timer >=1) {
   	 	$(obj).attr("disabled",true);
   	 	$(obj).text(timer+"S");
        timer--;
        setTimeout(function() {
            countSecond(obj,formId,type,timer);
        }, 1000);
    }
}
//ajax发送验证码 1-注册 2-找回密码 3-修改绑定手机号
function sendSmsRand(formId,type){
	var formUrl =ctx+"/res/uct/sendSmsCode?type="+type+"";
	var index_load = layer.load(1, {shade: false});
	var result = $.platform.submit({formId:formId,dataType:"json",url:formUrl});
	var flag = result.flag;
	var msg = result.msg;
	if("T"==flag){
		layer.close(index_load);
		layer.msg("短信验证码发送成功！", {offset: '200px'});
	}else{
		layer.close(index_load);
		layer.msg(result.msg, {offset: '200px'});
	}
}
/**
 *	注册用户名校验 
 */
function checkUserEname(formId){
	var userEnameStr ="#"+formId+"_login_username";
	var frm_checkName = "#"+formId+"_checkName";
	userEname = $(userEnameStr).val();
	if(strIsNull($(userEnameStr).val())){
		layer.tips($(userEnameStr).attr("tip"), userEnameStr, {tips: 1});
		$(userEnameStr).focus();
		return false;
	}
	if(!/^\w{6,20}/.test($(userEnameStr).val())){
		layer.tips('请输入6-20位数字字母下划线！', userEnameStr, {tips: 1});
		$(userEnameStr).focus();
		return false;
	}
	
	var formUrl = ctx+"/trans/list/?doCode=dymicSql";
	//var dataP = {'member.w_memberEname':userEname,'modelTypes':'s_member'};
	var dataP = {'uctUser.w_userEname':userEname,'modelTypes':'s_uctUser'};
	var result;
	$.ajax({url: formUrl,type: 'get',data:dataP,cache: false,async:false,dataType:'json',
		success: function(data){result=data;},error:function(messg)  { alert("错误信息:连接服务器失败");}  
	});
	if(result.total>0){
		$(frm_checkName).show();
		$(userEnameStr).focus();
		return false;
	}else{
		$(frm_checkName).hide();
	}
	return true;
	console.log();
}
/**
 *	找回密码用户名校验 
 */
function checkUserEnameByPass(formId){
	//发送验证码按钮不可用
	$("#sendRand").attr("readonly",true);
	var userEnameStr ="#"+formId+"_login_username";
	var mobile = "#"+formId+"_login_mobile";
	var mobile_show = "#"+formId+"_login_mobile_show";
	userEname = $(userEnameStr).val();
	if(strIsNull($(userEnameStr).val())){
		layer.tips($(userEnameStr).attr("tip"), userEnameStr, {tips: 1});
		$(userEnameStr).focus();
		return;
	}
	var formUrl = ctx+"/trans/list/?doCode=dymicSql";
	//var dataP = {'member.w_memberEname':userEname,'modelTypes':'s_member'};
	var dataP = {'uctUser.w_userEname':userEname,'modelTypes':'s_uctUser'};
	var result;
	$.ajax({url: formUrl,type: 'get',data:dataP,cache: false,async:false,dataType:'json',
		success: function(data){result=data;},error:function(messg)  { alert("错误信息:连接服务器失败");}  
	});
	if(result.total>0){
		var phone = result.rows[0].mobile;
		phone = phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
		$(mobile).val(result.rows[0].mobile);
		$(mobile_show).text(phone);
		$("#username").val(result.rows[0].userEname);
		$("#mobile").val(result.rows[0].mobile);
		$("#div1").hide();
		$("#div2").show();
	}else{
		$(mobile).val("");
		$(mobile_show).text("");
		$("#username").val("");
		$("#mobile").val("");
		layer.msg("账号不存在", {offset: '200px'});
	}
	console.log();
}
/**
 * 用户手机号校验
 * type 1 注册 2 找回密码 3 重新绑定手机号
 */
function checkUserMobile(formId,type){
	var mobile ="#"+formId+"_login_mobile";
	if(type=="3"){
		//判断是否和原手机号一样
		var oldMobile = $("#oldMobile").val();
		if(oldMobile==$(mobile).val()){
			layer.msg("新手机号不能与原手机号相同", {offset: '200px'});
			$(mobile).focus();
			return false;
		}
	}
	if(strIsNull($(mobile).val())){
		layer.tips($(mobile).attr("tip"), mobile, {tips: 1});
		$(mobile).focus();
		return false;
	}
	//验证手机号长度
	if(!checkMobileLen($(mobile).val())){
		layer.msg("手机号位数不足11位", {offset: '200px'});
		$(mobile).focus();
		return false;
	}
	//验证手机号
	if (!checkmobile($(mobile).val())){
		layer.msg("请输入正确的手机号", {offset: '200px'});
		$(mobile).focus();
		return false;
	}
	var formUrl = ctx+"/trans/list/?doCode=dymicSql";
	//var dataP = {'member.w_mobile':$(mobile).val(),'modelTypes':'s_member'};
	var dataP = {'uctUser.w_mobile':$(mobile).val(),'modelTypes':'s_uctUser'};
	var result;
	$.ajax({url: formUrl,type: 'get',data:dataP,cache: false,async:false,dataType:'json',
		success: function(data){result=data;},error:function(messg)  { alert("错误信息:连接服务器失败");}  
	});
	if(result.total>0){
		if(type=="1"){
			layer.msg("该手机号已被绑定", {offset: '200px'});
			return false;
		}else if(type=="2"){//找回密码填充userEname
			//$("#username").val(result.rows[0].memberEname);
		}else if(type=="3"){
			layer.msg("该手机号已被绑定", {offset: '200px'});
			return false;
		}
	}else{
		if(type=="2"){
			layer.msg("系统不存在该手机号", {offset: '200px'});
			$(mobile).val("");
			$(mobile).focus();
			return false;
		}
	}
	return true;
}
//找回密码校验-邮箱
function checkFindPassByEmail(){
	var userNameId ="#frm_login_username";
	var checkCodeId ="#frm_login_checkcode"; 
	if(strIsNull($(userNameId).val())){
		layer.tips($(userNameId).attr("tip"), userNameId, {tips: 2});
		$(userNameId).focus();
		return;
	}
	if(strIsNull($(checkCodeId).val())){
		layer.tips($(checkCodeId).attr("tip"), checkCodeId, {tips: 2});
		$(checkCodeId).focus();
		return;
	}
	$("#userEname").val($(userNameId).val().trim());
	$("#userRand").val($(checkCodeId).val());
	var formUrl =ctx+"/res/uct/findPwd";
	var index_load = layer.load(1, {shade: false});
	var result = $.platform.submit({formId:"findPassform_s",dataType:"json",url:formUrl});
	var flag = result.flag;
	var msg = result.msg;
	if("T"==flag){
		layer.close(index_load);
		layer.msg("密码找回申请成功，请等待邮件通知！", {offset: '100px'},function(){
			parent.layer.closeAll();
		});
	}else{
		layer.close(index_load);
		layer.msg(result.msg, {offset: '200px'});
	}
}
//找回密码校验-短信
function checkFindPassByMobile(){
	//var mobile ="#frm_findpass_login_mobile";
	var checkCodeId ="#frm_findpass_login_checkcode";  
	var passId ="#frm_findpass_login_pwd"; 
	var passId2 ="#frm_findpass_login_pwd2"; 
	//var userEname = $("#userEname").val();
	if(!/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/.test($(passId).val())){
		layer.tips('请输入6-24位密码，必须由数字和英文字母组成！', passId, {tips: 1});
		$(passId).focus();
		return;
	}
	if($(passId).val()!=$(passId2).val()){
		layer.tips("两次输入的密码不一致", passId2, {tips: 2});
		$(passId2).val("");
		$(passId2).focus();
		return;
	}
	//$("#mobile").val($(mobile).val().trim());
	$("#rand").val($(checkCodeId).val());
	$("#newPass").val($(passId).val().md5());
	var formUrl = ctx+"/res/uct/findPwdByMobile";
	var index_load = layer.load(1, {shade: false});
	var result = $.platform.submit({formId:"findPassform_s",dataType:"json",url:formUrl});
	var flag = result.flag;
	var msg = result.msg;
	if("T"==flag){
		layer.close(index_load);
		layer.alert("密码重置成功，您可以登录了！", {offset: '200px'},function(){
			parent.layer.closeAll();
		});
	}else{
		layer.close(index_load);
		layer.msg(result.msg, {offset: '200px'});
	}
}
//重置密码校验
function checkFindPassSub(){
	var passId ="#frm_login_password"; 
	var passId2 ="#frm_login_password2"; 
	var checkCodeId ="#frm_login_checkcode"; 
	/*
	if(strIsNull($(passId).val())){
		layer.tips($(passId).attr("tip"), passId, {tips: 2});
		$(passId).focus();
		return;
	}
	if($(passId).val().length<6){
		layer.tips("设置的密码不能太简单", passId, {tips: 2});
		$(userNameId).focus();
		return;
	}
	if(strIsNull($(passId2).val())){
		layer.tips($(passId2).attr("tip"), passId2, {tips: 2});
		$(passId2).focus();
		return;
	}
	*/
	if(!/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/.test($(passId).val())){
		layer.tips('请输入6-24位密码，必须由数字和英文字母组成！', passId, {tips: 1});
		$(passId).focus();
		return;
	}
	if($(passId).val()!=$(passId2).val()){
		layer.tips("两次输入的密码不一致", passId2, {tips: 2});
		$(passId2).val("");
		$(passId2).focus();
		return;
	}
	if(strIsNull($(checkCodeId).val())){
		layer.tips($(checkCodeId).attr("tip"), checkCodeId, {tips: 2});
		$(checkCodeId).focus();
		return;
	}
	
	$("#userPwd").val($(passId).val().md5());
	$("#userPwd2").val($(passId2).val().md5());
	$("#userRand").val($(checkCodeId).val());

	var formUrl =ctx+"/res/uct/editPwd";//统一注册form表单
	var index_load = layer.load(1, {shade: false});
	var result = $.platform.submit({formId:"findPassform_s",dataType:"json",url:formUrl});
	var flag = result.flag;
	var msg = result.msg;
	if("T"==flag){
		layer.close(index_load);
		layer.msg("密码修改成功，您可以登录了！", {offset: '200px'},function(){
			parent.layer.closeAll();
			window.close();
		});
	}else{
		layer.close(index_load);
		layer.msg(result.msg, {offset: '200px'});
	}
	
}
//注册校验
function validatorReg(){
	var mark = $("#J_regfrm").validate({
		submitHandler: function(form){//表单提交句柄,为一回调函数，带一个参数：form
			if(strIsNull($("#reg_username").val())){
				layer.tips('请输入邮箱！', '#reg_username', {tips: 1});
				$("#reg_username").focus();
				return;
			}
			if(strIsNull($("#reg_password").val())){
				layer.tips('请输入密码！', '#reg_password', {tips: 1});
				$("#reg_password").focus();
				return;
			}
			if(strIsNull($("#reg_password2").val())){
				layer.tips('请再次输入密码！', '#reg_password2', {tips: 1});
				$("#reg_password2").focus();
				return;
			}
			if($("#reg_password").val()!=$("#reg_password2").val()){
				layer.tips('两次输入的密码不一致', '#reg_password2', {tips: 1});
				$("#reg_password2").focus();
				return;
			}
			if(strIsNull($("#email_code").val())){
				layer.tips('请输入您的邮箱验证码！', '#email_code', {tips: 1});
				$("#email_code").focus();
				return;
			}
			$("#password").val($("#reg_password").val().md5());
			$("#password2").val($("#reg_password2").val().md5());
			$("#email").val($("#reg_username").val());
			var formUrl =ctx+"/res/uct/regUser";
   	 		layer.confirm('您确定要提交信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
   	 		, function(){
			var result = $.platform.submit({formId:'J_regfrm',dataType:'json',url:formUrl});
			//alert(result);
			if(result.flag=="T"){
				//layer.alert("注册成功，请登录！", {icon: 1,closeBtn: 0,offset: '220px'},function(){
				//	window.location.reload();
				//});
				layer.msg("注册成功，请登录！", {offset: '250px'});
			}else{
				//layer.alert(result.msg, {icon: 2,closeBtn: 0,offset: '220px'});
				layer.msg(msg, {offset: '250px'});
			}
   	 		}, function(){});
		},  
	    messages:{//可以自定义提示信息 
	    	username:{  
	     		required:"<font color='#fff'>请输入邮箱</font>",
				isMail:"<font color='#fff'>邮箱格式不正确</font>"
	        },
	        password:{
	        	required:"<font color='#fff'>请输入密码</font>",
				isPwd:"<font color='#fff'>长度在6-12之间，只能由字母、数字和下划线组成</font>"
	        },
	        password2:{
	        	required:"<font color='#fff'>请输入确认密码</font>",
	        	isPwd:"<font color='#fff'>长度在6-12之间，只能由字母、数字和下划线组成</font>"
	        },
	        emailCode:{
	        	required:"<font color='#fff'>请输入验证码</font>"
	        }
	    }  
	});
	return mark;
}


//登录退出返显
function opDone(flag,msg){
	//alert(flag+"-"+msg);
	if(flag=="T"){
		window.location=ctx+"/res/uct/toIndex?go="+ctx+"/index.jsp";
	}else{
		layer.msg(msg, {offset: '250px'});
	}
}

function strIsNull(str){
	 if(undefined==str || str==null){
		 return true;
	 }
	 if(""==str || str.length==0){
		 return true; 
	 }
	 return false;
 }

var sendMsgUrl =ctx+"/res/uct/sendCode";
var countdown=60; 
function findMoblieCode(ob) {
	//layer.tips('此功能未开放', "#"+$(ob).attr("id"), {tips: 1});
	document.getElementById("verifyCode2").style.visibility="visible"; 
	document.getElementById("verifyCode2").src ="/web/CheckRandCode?" + Math.random(); 
} 
function findEmailCode(val) { 
	if (countdown == 0) { 
		val.removeAttribute("disabled");    
		val.value="获取验证码"; 
		countdown = 60; 
	} else { 
		if(countdown == 60){
			var email =$("#reg_username").val();
			if(strIsNull(email)){
				layer.tips('请输入您的邮箱！', '#reg_username', {tips: 1});
				$("#reg_username").focus();
				return false;
			}
		   $.ajax({url:sendMsgUrl,data:{sendType:'mail',email:email},type: 'POST',cache: false,async:false,dataType:'json',
			   success: function(data){alert(data.msg);}
		   });
		}
		val.setAttribute("disabled", true); 
		val.value="重新发送(" + countdown + ")"; 
		countdown--; 
		setTimeout(function() { findEmailCode(val)},1000) 
   } 
} 

function sendMail(){
	var email =$("#reg_username").val();
	if(strIsNull(email)){
		layer.tips('请输入您的邮箱！', '#reg_username', {tips: 1});
		$("#reg_username").focus();
		return;
	}
   $.ajax({url:sendMsgUrl,data:{sendType:'mail',email:email},type: 'POST',cache: false,async:false,dataType:'json',
	   success: function(data){alert(data.msg);}
   });
}

/*** 网站导航登录/注册条 **/
//加载登录信息
/**
$(function(){
	 $.ajax({
	   url:ctx+'/common/top-index-js-ajax.jsp?v='+new Date().getTime(),
	   async:'true',success: function(data) {
		   alert(data);
		   $("#div_login_user").html(data);
	  }			       
});
});
**/
//退出前端
function logoutIndex(url){
	var defUrl = parent.location.href;
	var goUrl = strUtil.doNull(url,defUrl);
	layer.confirm('您确认要退出吗？', {btn: ['确认','取消'],closeBtn: 0,offset: '220px'}
		, function(){
			window.location = ctx+'/logout?go='+goUrl;
		}, function(){});	
}
//弹出登录框
var loginWin = null;
function loginIndex(f){
	var h = "400px";
	var w = "580px";
	if(undefined==f || f=="bjte"){
		f="bjte";
		h = "240px";
		w = "400px";
	}
	var sysName = f;
loginWin = layer.open({
    type: 2,
    title: '用户登录',
    shadeClose: false,
    shade: 0.6,
    area: [w, h],
    offset: '110px',
    content: ctx+'/sendPage/'+sysName+'/web/loginIndex' //iframe的url
}); 
}
function loginIndexJJ(){
	loginWin = layer.open({
	    type: 2,
	    title: '统一用户登录',
	    shadeClose: false,
	    shade: 0.6,
	    area: ['380px', '210px'],
	    offset: '200px',
	    content: ctx+'/sendPage/wbd/web/user/loginIndex' //iframe的url
	}); 
	}
function regIndex(){
if(null != loginWin) {
	layer.close(loginWin);
}
layer.open({
    type: 2,
    title: '快速注册',
    shadeClose: false,
	offset: '40px',
    shade: 0.6,
    area: ['580px', '510px'],
    content: ctx+'/sendPage/default/web/user/regIndex' //iframe的url
}); 
}
/*注册方式2*/
function regIndexT(){
	if(null != loginWin) {
		layer.close(loginWin);
	}
	//window.location = ctx+'/sendPage/bjte/web/user/regIndexT';
	//window.location = ctx+'sendPage/sale/web/user/regIndexT?sysFlag=bjte'
	window.location = ctx+'/sendPage/bjte/web/user/regIndex'
	/*
	layer.open({
	    type: 2,
	    title: '快速注册',
	    shadeClose: false,
		offset: '40px',
	    shade: 0.6,
	    area: ['580px', '510px'],
	    content: ctx+'/sendPage/default/web/user/regIndex' //iframe的url
	}); 
	*/
}
function resPassIndex(){
if(null != loginWin) {
	layer.close(loginWin);
}
layer.open({
    type: 2,
    title: '找回密码',
    shadeClose: false,
	offset: '40px',
    shade: 0.6,
    area: ['580px', '510px'],
    content: ctx+'/sendPage/bjte/web/user/resPassIndex' //iframe的url
}); 
}
//验证手机号
function checkmobile(th){
    if (th != ''){
           var t = /^0?(13[0-9]|15[012356789]|18[0-9]|17[0-9])[0-9]{8}$/;
        return t.test(th);
    }else{
        return false;
    }
}
//验证邮箱
function check_mail(str){
    var regex=new RegExp("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$");
    return regex.test(str);
}
//手机号长度11位
function checkMobileLen(th){
     if(th != ""){
         var t = /^(\d{11})$/;
         return t.test(th);
     }else{
        return false; 
     }
}



//身份证号合法性验证 
//支持15位和18位身份证号
//支持地址编码、出生日期、校验位验证\
//var c = '130981199312253466';
//var res= IdentityCodeValid(c);
  function IdentityCodeValid(code) { 
      var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
      var tip = "";
      var pass= true;
      
      if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)){
          tip = "身份证号格式错误";
          pass = false;
      }
      
     else if(!city[code.substr(0,2)]){
          tip = "地址编码错误";
          pass = false;
      }
      else{
          //18位身份证需要验证最后一位校验位
          if(code.length == 18){
              code = code.split('');
              //∑(ai×Wi)(mod 11)
              //加权因子
              var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
              //校验位
              var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
              var sum = 0;
              var ai = 0;
              var wi = 0;
              for (var i = 0; i < 17; i++)
              {
                  ai = code[i];
                  wi = factor[i];
                  sum += ai * wi;
              }
              var last = parity[sum % 11];
              if(parity[sum % 11] != code[17]){
                  tip = "校验位错误";
                  pass =false;
              }
          }
      }
      if(!pass) layer.tips(tip);
      return pass;
  }